package model

type CmdResult struct {
	RetCode int    `json:"ret_code"`
	Stdout  string `json:"stdout"`
	Stderr  string `json:"stderr"`
	Message string `json:"message"`
}

type TaskResumeRequest struct { // 任务恢复请求
	JobId   string `json:"job_id"`
	StepNum int    `json:"step_num"`
	Action  string `json:"action"`
}

type TaskRetryRequest struct { // 任务重试请求
	JobId    string `json:"job_id"`
	NewJobId string `json:"new_job_id"`
	StepNum  int    `json:"step_num"`  // 开始重试的步骤号，0表示从头开始
	ReuseEnv bool   `json:"reuse_env"` // 是否复用环境
}

const (
	// 父作业状态码
	JobSuccessCode    = "30010"
	JobProcessingCode = "30020"
	JobRunningCode    = "30030"
	JobNotRunCode     = "30040"
	JobFailedCode     = "30050"
	JobTimeoutCode    = "30060"
	JobCanceledCode   = "30070"
	// 父作业
	JobSuccess    = "执行成功"
	JobProcessing = "待处理"
	JobRunning    = "执行中"
	JobNotRun     = "未执行"
	JobFailed     = "执行异常"
	JobTimeout    = "超时终止"
	JobCanceled   = "已取消"

	// 子作业
	SubJobSuccess    = "执行成功"
	SubJobProcessing = "待处理"
	SubJobRunning    = "执行中"
	SubJobNotRun     = "未执行"
	SubJobFailed     = "执行异常"
	SubJobTimeout    = "超时终止"
	SubJobCanceled   = "已取消"

	// 作业类型
	JobTypeManual = "手动执行"
	JobTypeCron   = "定时执行"

	// 步骤类型
	StepTypeExecTask       = "任务"
	StepTypeManualReview   = "人工处理"
	StepTypeProcessControl = "流程控制"

	// 恢复操作类型
	ResumeActionContinue = "继续"
	ResumeActionSkip     = "跳过"
	ResumeActionCancel   = "取消"

	// 重试模式
	RetryModeFromStart = 0 // 从头开始重试
	RetryModeFromStep  = 1 // 从指定步骤开始重试
)

var JobCodeMap = map[string]string{
	JobNotRun:     JobNotRunCode,
	JobProcessing: JobProcessingCode,
	JobRunning:    JobRunningCode,
	JobSuccess:    JobSuccessCode,
	JobFailed:     JobFailedCode,
	JobTimeout:    JobTimeoutCode,
	JobCanceled:   JobCanceledCode,
}

func GetJobCodeByStatus(status string) string {
	if code, ok := JobCodeMap[status]; ok {
		return code
	}
	return JobFailedCode
}
